#include "game.h"
Game * Game::gamePtr = nullptr;
Game::Game()
{

}
Game::~Game()
{
    delete mwPtr;
}

void Game::start()
{
    MainWindow *mwPtr = new MainWindow;
    mwPtr->readSize();
LOOP:mwPtr->init();
     string begin = COLOR_BLACK;
     int row,column;
     bool ret;

     while(1)
     {
         mwPtr->showChessBoard();
         string message = " please enter a point,such as:3 4";
         message = begin + message;
         mwPtr->showMessageBox(message);
         cin>>row>>column;
         ret = mwPtr->insert(row,column,begin);
         if(!ret){
             message = "this point is repeat or outofrange,please try again";
             mwPtr->showMessageBox(message);
             continue;
         }
         //判断输赢
         //TODO
         ret = mwPtr->isWinner(row,column,begin);
         if(ret)
         {
             //如果赢了
             mwPtr->showChessBoard();
             //显示分数
             message = mwPtr->getScore();
             mwPtr->showMessageBox(message);
             message = " is WINNER. Do you want one more time? y or n";
             message = begin + message;
             mwPtr->showMessageBox(message);
             string ack;
             cin>>ack;
             if(ack == "y")
             {
                 goto LOOP;
             }else{
                 break;
             }

         }
         if(begin == COLOR_BLACK)
         {
             begin = COLOR_WHITE;
         }else if(begin == COLOR_WHITE)
         {
             begin = COLOR_BLACK;
         }
     }

}

bool Game::resume(){
    return false;
}

void Game::end()
{


}


Game* Game::getGame()
{
    if(Game::gamePtr == nullptr)
    {
        Game::gamePtr = new Game;
    }
    return Game::gamePtr;
}
